//
//  CommentTableViewCell.m
//  CapriceMusic
//
//  Created by 蒋恩浩 on 16/1/8.
//  Copyright © 2016年 MYX. All rights reserved.
//

#import "CommentTableViewCell.h"

@interface CommentTableViewCell ()

@property (nonatomic, strong) UIImageView *userHeadImgView;
@property (nonatomic, strong) JEHLabel *userNameLabel;
@property (nonatomic, strong) JEHLabel *contentLabel;
@property (nonatomic, strong) JEHLabel *dateCreatedLabel;
@property (nonatomic, strong) JEHLabel *goodCountLabel;
@property (nonatomic, strong) UIImageView *vipImgView;

@end

@implementation CommentTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
        self.userHeadImgView = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.userHeadImgView.contentMode = UIViewContentModeScaleAspectFill;
        self.userHeadImgView.clipsToBounds = YES;
        self.userHeadImgView.layer.masksToBounds = YES;
        self.userHeadImgView.layer.cornerRadius = 25;
        self.userNameLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:14 withTextColor:[UIColor colorWithRed:230 / 255.0 green:230 / 255.0 blue:230 / 255.0 alpha:1.0]];
        self.contentLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:16 withTextColor:[UIColor whiteColor]];
        self.contentLabel.numberOfLines = 0;
        self.dateCreatedLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:14 withTextColor:[UIColor colorWithRed:230 / 255.0 green:230 / 255.0 blue:230 / 255.0 alpha:1.0]];
        self.goodCountLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:14 withTextColor:[UIColor colorWithRed:230 / 255.0 green:230 / 255.0 blue:230 / 255.0 alpha:1.0]];
        self.vipImgView = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.hotLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:14 withTextColor:[UIColor whiteColor]];
        self.hotLabel.textAlignment = NSTextAlignmentCenter;
        self.hotLabel.backgroundColor = [UIColor redColor];
        self.hotLabel.text = @"hot";
        self.hotLabel.layer.masksToBounds = YES;
        self.hotLabel.layer.cornerRadius = 15;
        
        [self addSubview:self.userHeadImgView];
        [self addSubview:self.userNameLabel];
        [self addSubview:self.contentLabel];
        [self addSubview:self.dateCreatedLabel];
        [self addSubview:self.goodCountLabel];
        [self addSubview:self.vipImgView];
        [self addSubview:self.hotLabel];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.userHeadImgView.frame = CGRectMake(10, 10, 50, 50);
    self.userNameLabel.frame = CGRectMake(70, 25, [self.userNameLabel getWidthWithFont:14], 20);
    self.contentLabel.frame = CGRectMake(20, 70, self.width - 40, self.height - 140);
    self.dateCreatedLabel.frame = CGRectMake(10, self.height - 60, [self.dateCreatedLabel getWidthWithFont:14], 50);
    self.goodCountLabel.frame = CGRectMake(self.width - [self.goodCountLabel getWidthWithFont:14] - 10, self.height - 60, [self.goodCountLabel getWidthWithFont:14], 50);
    self.hotLabel.frame = CGRectMake(self.width - 40, 20, 30, 30);
    self.vipImgView.frame = CGRectMake(self.userNameLabel.width + 70, 25, 20, 20);
}

- (void)setDetailCommentModel:(DetailCommentModel *)detailCommentModel {
    
    if (_detailCommentModel != detailCommentModel) {
        
        _detailCommentModel = detailCommentModel;
    }
    [self.userHeadImgView sd_setImageWithURL:[NSURL URLWithString:detailCommentModel.userHeadImg]];
    self.userNameLabel.text = detailCommentModel.userName;
    self.contentLabel.text = detailCommentModel.content;
    self.dateCreatedLabel.text = detailCommentModel.dateCreated;
    self.goodCountLabel.text = [NSString stringWithFormat:@"👍🏿 %d", detailCommentModel.totalSupports.intValue];
    [self.vipImgView sd_setImageWithURL:[NSURL URLWithString:detailCommentModel.userWoImg]];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end















